
mixin link(href, name)
  a(href=href)= name


extends ../_layout
block content
   div
      h1= 'Message Board'
      h2= 'Share your ideas, knowledges, stories ...'
      br
      br
      br

   hr

   if(messages)
      - each message in messages
         if(message)
            div
               b 
                  apan= '[' + message.title + '] ' 
               if(user && user.role && user.role=='admin')
                  a(href='/messages/edit/' + message._id)= 'Edit'

               - var msgbody = message.body
               - msgbody = msgbody.replace(/(?:<)/g, '&lt;');
               - msgbody = msgbody.replace(/(?:>)/g, '&gt;');
               //- msgbody = msgbody.replace(/(?:\r\n|\r|\n)/g, '<br />');
               //span!= msgbody
               pre= msgbody

               span= 'posted by: ' 
               +link('/users/profile/' + message.poster._id, message.poster.firstname)
               span= ' @ ' + message.date

               br
               br
               br
               br



   if(user && user.role && (user.role=='admin' || user.role=='manager' || user.role=='official') )
      div.well
         form(method='post')
            div.form-group
               div: input.form-control(type='text', name='title', placeholder='Message Title')
               div: textarea.form-control(rows='4', name='body', placeholder='Message Body')
            input.btn.btn-primary(type='submit', value='Post')

   if(!user)
      div.well
         form.navbar-form(action='/users/login', method='post')
            div.form-group
               input.form-control(type='text', name='email', placeholder='Email')
               input.form-control(type='password', name='password', placeholder='Password')
            input.btn.btn-success(type='submit', value='Login')
         
